package com.sy.demo.mapper;

import com.sy.demo.model.Resume;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author songyi
 * @date 2020/6/15 0015 23:59
 * @description 一个符合SpringJPA要求的Dao层是需要集成 JpaRepository<T, ID>, JpaSpecificationExecutor<T>
 * JpaRepository<操作的实体类型,主键类型>，封装了基本的 CRUDE 操作
 * JpaSpecificationExecutor<操作的实体类型>
 */
public interface ResumeMapper extends JpaRepository<Resume, Long>, JpaSpecificationExecutor<Resume> {

    @Query("from Resume where id = ?1 and name = ?2")
    List<Resume> findByJpql(Long id, String name);

    @Query(value = "SELECT * FROM tb_resume where name like ?1 and address like ?2 ", nativeQuery = true)
    List<Resume> findBySql(String name, String address);

    /**
     * 方法命名规则查询
     * 方法名以 findBy 开头，属性首字母大写，查询方式（模糊查询，等价查询）默认是等价查询
     * @param name
     * @return
     */
    List<Resume> findByNameLikeAndAddress(String name, String address);
}
